package com.product.magina.webserviceclient.service;

import com.alibaba.fastjson.JSON;
import com.magina.common.model.DemoModel;
import com.magina.common.model.UserInfo;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.jws.WebService;
import java.util.List;

/**
 * webservice测试接口实现
 * @author：anti_magina
 * @date：2019-03-29 10:16:30
 */
@WebService(serviceName = "TestService", // 与接口中指定的name一致
targetNamespace = "http://service.webserviceclient.magina.product.com", // 与接口中的命名空间一致,一般是接口的包名倒
endpointInterface = "com.product.magina.webserviceclient.service.TestService"// 接口地址
)
@Component
public class TestServiceImpl implements TestService {

    @Override
    public String sendMessage(String username) {
        System.out.println("in_userName : " +username);
        return "hello "+username;
    }

    @Override
    public String sendMessage(String username, String id) {
        System.out.println("in_userName : " +username +",in_id :" + id);
        return "hello "+username +  "your id is: " + id;
    }

    @Override
    public String saveMessage(String model) {
        DemoModel demoModel = JSON.parseObject(model,DemoModel.class);

        if(StringUtils.isEmpty(demoModel.getId())){
            return "N";
        }
        System.out.println(demoModel.getId());
        System.out.println(demoModel.getUserName());
        return "Y";
    }

    @Override
    public String getUserName(String username) {
        System.out.println("Method:"+Thread.currentThread().getStackTrace()[1].getMethodName() + " + param:" +username);
        return username;
    }

    @Override
    public UserInfo getUser(UserInfo user) {
        // TODO 自动生成的方法存根
        System.out.println("Method:"+Thread.currentThread().getStackTrace()[1].getMethodName() + " + param:" +user.toString());
        return user;
    }

    @Override
    public List<UserInfo> getUserList(List<UserInfo> userList) {
        // TODO 自动生成的方法存根
        System.out.println("Method:"+Thread.currentThread().getStackTrace()[1].getMethodName() + " + param:" +userList);
        return userList;
    }

    @Override
    public List<UserInfo> getUserListByName(List<UserInfo> userList, String userName) {
        System.out.println("Method:"+Thread.currentThread().getStackTrace()[1].getMethodName() + " + param:" +userName);
        if(!CollectionUtils.isEmpty(userList)){
            userList.stream().forEach(p ->{
                if(!userName.equals(p.getUserName())){
                    p.setUserName(userName);
                }else{
                    p.setUserName("重复名字!");
                }
            });
        }
        return userList;
    }


}
